package com.yanyeori.framework.core.manager;

import com.yanyeori.framework.core.thread.AsyncManager;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PreDestroy;

/**
 * 确保应用退出时能关闭后台线程
 */
@Slf4j
public class ShutdownManager {

    @PreDestroy
    public void destroy() {
        shutdownAsyncManager();
    }

    /**
     * 停止异步执行任务
     */
    private void shutdownAsyncManager() {
        try {
            AsyncManager.shutdown();
        } catch (Exception e) {
            log.error("shutdownAsyncManager", e);
        }
    }
}
